// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Global, { CHANNEL, PLATFORM } from "../lib/Global";
import StartUp from "../lib/StartUp";
import CM from "../lib/cache/CM";
import SceneMgr from "../lib/scene/SceneMgr";
import DBattle from "./cache/DBattle";
import DField from "./cache/DField";
import DUser from "./cache/DUser";
import WebPlatform from "./platform/WebPlatform";
import GameScene from "./scenes/GameScene";
import HallScene from "./scenes/HallScene";


const {ccclass, property} = cc._decorator;

@ccclass
export default class RoguelikeStartUp extends StartUp {
    protected initPlatform(completedCallback) {
        if (cc.sys.os == cc.sys.OS_WINDOWS || cc.sys.os == cc.sys.OS_OSX) {
            console.error("初始化平台 os")
            if (!cc.sys.isNative) {
                Global.platformType = PLATFORM.WEB;
                console.error("初始化平台 os web")
            } else {
                Global.platformType = PLATFORM.WINDOWS;
            }
        }
        if (cc.sys.os == cc.sys.OS_ANDROID)  {
            if (!cc.sys.isNative) {
                Global.platformType = PLATFORM.WEB;
            } else {
                Global.platformType = PLATFORM.ANDROID;
            }
        }
        if (cc.sys.os == cc.sys.OS_IOS)  {
            if (!cc.sys.isNative) {
                Global.platformType = PLATFORM.WEB;
            } else {
                Global.platformType = PLATFORM.IOS;
            }
        }
        
        if (Global.channel == CHANNEL.WECHAT) {
            console.warn("当前平台微信");
            Global.platform = new WebPlatform();
        } else if (Global.platformType == PLATFORM.WEB) {
            console.warn("当前平台WEB");
            Global.platform = new WebPlatform();
        } else if (Global.platformType == PLATFORM.WINDOWS) {
            console.warn("当前平台Windows");
        } else if (Global.platformType == PLATFORM.ANDROID) {
            console.warn("当前平台Android");
        } else if (Global.platformType == PLATFORM.IOS) {
            console.warn("当前平台IOS");
        }
        completedCallback && completedCallback();
    }
    protected startGame(): void {
        SceneMgr.ins(SceneMgr).replaceScene(HallScene);
    }

    protected initUserData(completedCallback: any): void {
        CM.ins(CM).create(DUser);
        CM.ins(CM).create(DBattle);
        CM.ins(CM).create(DField);
        completedCallback&&completedCallback();
    }

    
}
